<template>
  <div>
    <!-- 头部导航栏 -->
    <div>
      <header class="home-header wrap" :class="{ activec: headerActive }">
        <i class="iconfont icon-caidan">
          <van-icon name="wap-nav" />
        </i>
        <div class="header-search">
          <span class="app-name">G</span>
          <i class="iconfont icon-search"><van-icon name="search" /></i>
          <span class="search-title">家电返场同价11.11</span>
        </div>
        <span v-if="!$store.getters.getIsLogin" @click="$router.push('/login')"
          >登录</span
        >
        <span v-else @click="$router.push('/user')"
          ><van-icon name="manager-o" class="icon-manager"
        /></span>
      </header>
    </div>

    <!-- 轮播 -->
    <div>
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
        <van-swipe-item v-for="(item, index) in images" :key="index">
          <img :src="images[index].imgUrl" class="swiper_img" />
        </van-swipe-item>
      </van-swipe>
    </div>
    <!-- 导航内容 -->

    <div class="topnave">
      <van-grid :column-num="5">
        <van-grid-item
          v-for="(item, index) in categoryimg"
          :key="index"
          :icon="item.imgUrl"
          :text="item.name"
          @click="$router.push('/product-list')"
        />
      </van-grid>
    </div>
    <!-- 内容 -->

    <section class="floor-list">
      <div
        class="floor-wrap"
        v-for="proItem in neironglist"
        :key="proItem.headUrl"
      >
        <img :src="proItem.headUrl" class="floor-head" />
        <div class="floor-content">
          <div
            class="floor-category"
            v-for="item in proItem.list"
            :key="item.title"
          >
            <p>{{ item.title }}</p>
            <p>{{ item.desc }}</p>
            <div class="floor-products">
              <img
                v-for="(imgs, index) in item.products"
                :key="index"
                :src="imgs.imgUrl"
              />
            </div>
          </div>
        </div>
      </div>
    </section>
    <!-- 底部导航栏 -->
    <div>
      <tab-bar :active="0"></tab-bar>
    </div>
  </div>
</template>
<script>
import tabBar from "@/components/tabBar.vue";
import { getSliders, homeCategory, neilist } from "../../api";
export default {
  components: {
    tabBar,
  },
  data() {
    return {
      active: 0,
      images: [],
      categoryimg: [],
      neironglist: [],
      headerActive: false,
    };
  },
  mounted() {
    // 添加滚动事件
    window.addEventListener("scroll", this.pageScroll);
  },
  methods: {
    pageScroll() {
      // 获取滚动距离
      let scrollTop =
        window.pageYOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop;
      scrollTop > 100
        ? (this.headerActive = true)
        : (this.headerActive = false);
    },
  },
  created() {
    getSliders((res) => {
      //   console.log(res);
      this.images = res.data;
      //   console.log("aaa",this.images);
    });

    homeCategory((res) => {
      //   console.log("首页分类数据：", res.data);
      this.categoryimg = res.data;
    });
    neilist((res) => {
      //   console.log("内容数据数据：", res.data);
      this.neironglist = res.data;
    });
  },
};
</script>

<style lang="scss">
.activec {
  background-color: red;
}

.topnave .van-icon__image {
  font-size: 80px;
}

.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  height: 400px;
  background-color: #39a9ed;
}
.swiper_img {
  width: 100%;
  height: 100%;
}
.van-swipe__indicators {
  bottom: 82px;
}
@import "../../common/mixin";
.home-header {
  position: fixed;
  left: 0;
  top: 0;
  @include fj;
  width: 100%;
  height: 100px;
  line-height: 100px;
  padding: 0 30px;
  @include boxSizing;
  font-size: 30px;
  color: #fff;
  z-index: 10000;

  .icon-caidan {
    font-size: 50px;
  }
  .icon-manager {
    font-size: 40px;
  }

  .header-search {
    display: flex;
    width: 74%;
    height: 40px;
    line-height: 40px;
    margin: 20px 0;
    padding: 10px 0;
    color: #232326;
    background: #fff;
    @include borderRadius(40px);

    .app-name {
      padding: 0 20px;
      color: $red;
      font-size: 40px;
      font-weight: bold;
      border-right: 1px solid #666;
    }

    .icon-search {
      padding: 0 20px;
      font-size: 34px;
    }

    .search-title {
      font-size: 24px;
      color: #666;
    }
  }

  .icon-iconyonghu {
    font-size: 44px;
  }
}

.floor-list {
  width: 100%;
  padding-bottom: 100px;

  .floor-head {
    width: 100%;
    height: 80px;
    background: #f6f6f6;
  }

  .floor-content {
    display: flex;
    flex-shrink: 0;
    flex-wrap: wrap;
    width: 100%;
    @include boxSizing;

    .floor-category {
      width: 50%;
      padding: 20px;
      border-right: 1px solid #dcdcdc;
      border-bottom: 1px solid #dcdcdc;
      @include boxSizing;

      &:nth-child(2n) {
        border-right: none;
      }

      p {
        font-size: 34px;
        color: #333;

        &:nth-child(2) {
          padding: 10px 0;
          font-size: 26px;
          color: $red;
        }
      }

      .floor-products {
        display: flex;
        justify-content: space-around;
        width: 100%;

        img {
          width: 130px;
          height: 130px;
        }
      }
    }
  }
}
</style>